package com.shanyu.wechat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shanyu.wechat.entity.JianDaoYunEntity;
import com.shanyu.wechat.mapper.JianDaoYunMapper;
import com.shanyu.wechat.service.JianDaoYunService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 实时同步任务Service实现
 */
@Service
@RequiredArgsConstructor
public class JianDaoyunServiceImpl extends ServiceImpl<JianDaoYunMapper, JianDaoYunEntity> implements JianDaoYunService {


    @Override
    public IPage<JianDaoYunEntity> getPage(Page<JianDaoYunEntity> page, Map<String, Object> params) {
        QueryWrapper<JianDaoYunEntity> wrapper = new QueryWrapper<>();

        String message = MapUtils.getString(params, "message");
        Integer isMatch = MapUtils.getInteger(params, "isMatch");

        wrapper.like(StringUtils.isNotEmpty(message), "message", message);
        wrapper.eq(isMatch != null, "is_match", isMatch);
        wrapper.orderByDesc("create_time");

        return this.page(page, wrapper);
    }
}
